﻿using HMaker.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace HMaker.Dialogs
{
    public partial class FindPicResultDialog : Form
    {
        public FindPicResultDialog()
        {
            InitializeComponent();
        }

        public FindPicResultDialog(Point basePoint, Point[] points):this()
        {
            TB_BasePoint.Text = basePoint.MakeString();
            foreach (var point in points)
                LB_Main.Items.Add($"{point.MakeString()}({point.Sub(basePoint).MakeString()})");
        }

        /// <summary>
        /// 当前选择的数据条目
        /// </summary>
        private string CurItem;

        private void CMS_Main_Opening(object sender, CancelEventArgs e)
        {
            if (LB_Main.SelectedItem is string item)
            {
                CurItem = item;
            }
            else
            {
                e.Cancel = true;
            }
        }

        private void TSMI_CopyPoint_Click(object sender, EventArgs e)
        {
            if (CurItem != null)
            {
                Clipboard.SetText(Regex.Replace(CurItem, @"(-?\d+,-?\d+)\(-?\d+,-?\d+\)", "$1"));
            }
        }

        private void TSMI_CopyBaseOffset_Click(object sender, EventArgs e)
        {
            if (CurItem != null)
            {
                Clipboard.SetText(Regex.Replace(CurItem, @"-?\d+,-?\d+\((-?\d+,-?\d+)\)", "$1"));
            }
        }
    }
}
